﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace Utilities
{
    public class CookieManager
    {
        public static Boolean IsAdmin
        {
            get
            {
                try
                {
                    if (HttpContext.Current.Request.Cookies["IsAdmin"].Value != null)
                        return Convert.ToBoolean(HttpContext.Current.Request.Cookies["IsAdmin"].Value.ToString());
                    else
                        return false;
                }
                catch
                {
                    return false;
                }
            }
            set
            {
                HttpContext.Current.Response.Cookies["IsAdmin"].Value = value.ToString();
            }
        }

        public static String UserName
        {
            get
            {
                try
                {
                    if (HttpContext.Current.Request.Cookies["UserName"].Value != null)
                        return HttpContext.Current.Request.Cookies["UserName"].Value.ToString();
                    else
                        return String.Empty;
                }
                catch
                {
                    return String.Empty;
                }
            }
            set
            {
                HttpContext.Current.Response.Cookies["UserName"].Value = value;
            }
        }

        public static String LOGGED_IN_USER_ID
        {
            get
            {
                try
                {
                    if (HttpContext.Current.Request.Cookies["LOGGED_IN_USER_ID"].Value != null)
                        return HttpContext.Current.Request.Cookies["LOGGED_IN_USER_ID"].Value.ToString();
                    else
                        return String.Empty;
                }
                catch
                {
                    return String.Empty;
                }
            }
            set
            {
                HttpContext.Current.Response.Cookies["LOGGED_IN_USER_ID"].Value = value;
            }
        }

        public static String AdminId
        {
            get
            {
                try
                {
                    if (HttpContext.Current.Request.Cookies["AdminId"].Value != null)
                        return HttpContext.Current.Request.Cookies["AdminId"].Value.ToString();
                    else
                        return String.Empty;
                }
                catch
                {
                    return String.Empty;
                }
            }
            set
            {
                HttpContext.Current.Response.Cookies["AdminId"].Value = value;
            }
        }

        public static Boolean IsLoggedout
        {
            get
            {
                try
                {
                    if (HttpContext.Current.Request.Cookies["_IsLoggedout"].Value != null)
                        return Convert.ToBoolean(HttpContext.Current.Request.Cookies["_IsLoggedout"].Value.ToString());
                    else
                        return false;
                }
                catch
                {
                    return false;
                }
            }
            set
            {
                HttpContext.Current.Response.Cookies["_IsLoggedout"].Value = value.ToString();
                HttpContext.Current.Response.Cookies["_IsLoggedout"].Expires = DateTime.Now.AddHours(1);
            }
        }
    }
}
